$(function () {
    loadFoot(0);
    share();
    $.ajax({
        url: host + 'mtmlapi/GetWxQrCode?path=pages/fakeIndex/fakeIndex&openid='+openid,
        type:'GET',
        dataType: 'JSON',
        success: function (res) {
            if (res.state) {
                $('.sucSign>img').attr('src', res.data)
            }
        }
    })
    $('.qrcode-btn').on('click',function () {
        $('.modal').addClass('trf')
    })
    $('.modal').click(function () {
        $(this).removeClass('trf')
    })
    //TODO:添加绩效数据
    $.ajax({
        url:host+'/CMSAPI/GetPartnerMoney?openid='+openid+'&cid='+cid,
        success:function(data){
            if(data.state){
                var NotCash=data.data.NotCash||0;
                var AlreadyCash=data.data.AlreadyCash||0;
                $('.totalIncome>.a2').html(NotCash)
                $('.totalIncome>.a3').html('累计提现金额：'+AlreadyCash)
            }
        }
    })
    //TODO:加载三个按钮
    $.ajax({
        url:host+'/CMSAPI/CategoryByLevel?cid='+cid+'&id=160&menuID=5&level=2',
        type:'GET',
        success:function(data){
            if(data.state){
                var menuList=data.data;
                var menuLen=menuList.length;
                var menuWidth=(100/menuLen).toFixed(1)+'%'
                var html='';
                $.each(menuList,function(i,menu){
                    var GroupName=menu.GroupName||'';
                    var imgUrl=menu.Img||'';
                    var URL=menu.Url||'javascript:void (0)';
                    html+='<li class="menu'+i+'" style="width: '+menuWidth+'">'
                    html+='    <a href="'+URL+'">'
                    html+='    <span><img src="'+imgUrl+'" alt="" ></span>'
                    html+='    <p>'+GroupName+'</p>'
                    html+='</a></li>'
                })
                $('.menuList').append(html);
            }
        }
    })
    //TODO:最近订单加载
    var index=0;
    var size=10;
    var message=0;
    var time='2017/7/11 15:07:29';
    // var fid=ddid||did;//第一次进来时间初始化的第一列表id  first id
    $('.orderBox').dropload({
        scrollArea:window,
        distance:50,
        domUp:{
            domClass : 'dropload-up',
            domRefresh : '<div class="dropload-refresh">↓下拉刷新</div>',
            domUpdate : '<div class="dropload-update">↑释放更新</div>',
            domLoad : '<div class="dropload-load"><span class="loading"></span>加载中...</div>'
        },
        domDown:{
            domClass : 'dropload-down',
            domRefresh : '<div class="dropload-refresh">↑上拉加载更多</div>',
            domLoad : '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
            domNoData : '<div class="dropload-noData">已经到底了，别扯了</div>'
        },
        loadDownFn:function(me){
            index++;
            message++;
            $.ajax({
                url:host+'/mtmlapi/UserOrderList?openid='+openid+'&cid='+cid+'&index='+index+'&size='+size,
                type:'GET',
                dataType:'JSON',
                success:function(data){
                    if(data.state){
                        var msgNum =Math.ceil(data.data.count/size);
                        if (message <=msgNum){
                            var html3='';
                            var list3=data.data.OrderList;
                            $.each(list3,function(i,obj){
                                var buy_name=obj.buy_name||"";
                                var order_id=obj.order_id;
                                var order_time=obj.order_time||'';
                                var order_state=obj.order_state||'';
                                var name=obj.name||'';
                                var count=obj.count||'';
                                var price=obj.price||'';
                                var productId=obj.productId||'';
                                html3+='<tr>'
                                html3+='    <td>'+order_id+'</td>'
                                html3+='    <td>'+buy_name+'</td>'
                                html3+='    <td>'+order_time.split(' ')[0]+'</td>'
                                html3+='    <td>'+order_state+'</td>'
                                html3+='</tr>'
                            });
                            $('.orderList').append(html3);
                        }else {
                            me.lock();
                            me.noData();
                        }
                    }else {
                        alert('网络繁忙，请稍后重试！')
                    }
                    me.resetload();
                }
            })
        }
        // loadUpFn:function(me){
        //     location.reload();
        //     me.resetload();
        // }
    });
})
